<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	// 实现一个请求函数：fetchWithRetry，要求会最多自动重试 3 次，任意一次成功就直接返回
	function fetchWithRetry(url,options,maxRetry){
		return new Promise((resolve,reject) => {
			const doFetch = async (currentTimes) => {
				try {
					const response = await fetch(url,options)
					if(response.ok){
						resolve(response)
					} else {
						throw new Error('Request failed')
					}
				} catch(e){
					if(currentTimes < maxRetry){
						await doFetch(currentTimes + 1)
					} else {
						reject(e)
					}
				}
			}
			doFetch(1)
		})
	}
</script>
</html>